import TableLyout from '@/components/commonPublic/tableLyout.vue'
import TableData from "@/components/public/el-table"; //主页面列表
import actions from "@/actions";

import CustomDialog from "@/components/materialDataManage/categoryManagement/index.vue";
import {
    getSpeciesDataList, //列表页接口
} from "@/api/request.js";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import formJs from "./regexDetail.js"; //新增弹框配置

export default {
    name: "categoryManagement",
    data() {
        return {
            name: "categoryManagement",
            expandRows: [], // 展开数组

            isLock: false,
            projectId: null,
            projectName: null,
            loading: false,
            btnObj: [], //按钮
            queryCriteriaData: {}, //分页
            navigatepageNums: null,
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            radio: "待办",
            // 列表
            getList: {
                page: 1,
                pageSize: 15,
                name: "", //材料种类/名称
                fVersion: "" //规格型号
            },
            pageSizes:  [15, 30,45, 60],
            isShow: false, //是否显示弹框

            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            activeIndex: "1",
            fId: null, //当前数据fId
            tableData: [],
            companyId: null,
            currentRowId: "",
            dialogTitle: null,
        };
    },
    computed: {
        hIndex() {
            // 当前页数 - 1 * 每页数据条数 + 1
            return (this.getList.page - 1) * this.getList.pageSize + 1
        }
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        elBreadcrumb,
        CustomDialog
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
        this.yj_searchForm(this.getList, 1);
        
    },
    methods: {
        // 页面切换
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.getList.page = val;
            this.yj_searchForm(this.getList);
        },
        refreshList(status) { //刷新列表
            if (status == 0) {
                this.isShow = true;
            }
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        closeDialog() {
            this.isShow = false;
        },
        handleRow() {},

        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 点击查看
        yj_viewForm(row, label) {
            if (label == "材料种类") {
                this.statusNum = 7
                this.isShow = true;
                this.currentRow = row;
                this.dialogTitle = '材料种类查看'


            } else if (label == "材料名称") {
                this.statusNum = 7
                this.isShow = true;
                this.currentRow = row;

                this.dialogTitle = '材料名称查看'
            }
        },
        // 新增/编辑
        yj_edit(num) {

            this.statusNum = num
            num == 1 || num == 2 ? this.dialogTitle = '材料种类编辑' : num == 4 || num == 5 ? this.dialogTitle = '材料名称编辑' : this.dialogTitle = ""
            if (num == 7) { //查看
                if (this.dataFid != null) {
                    if (this.currentRow.materialList) {
                        this.dialogTitle = '材料种类查看'
                    } else {
                        this.dialogTitle = '材料名称查看'
                    }
                    this.statusNum = 7
                    this.isShow = true;

                } else {
                    this.$message.warning("请先选择需要删除的数据");
                }
            }

        },
        editText() {
            this.isShow = true;
        },


        // 查看

        // 点击当前行变色
        rowChange(val, expandedRows) {
            this.currentRow = val
            this.dataFid = val.fId;
            if (expandedRows.length > 1) {
                this.$refs.chartTable.toggleRowExpansion(expandedRows[0])
            }
        },
        // 获取列表数据
        yj_searchForm(data) {
            var obj = {
                page: data.page,
                pageSize: 15
            }
            this.loading = true;
            var that = this;
            getSpeciesDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                        that.navigatepageNums =
                            res.data.pageInfo.navigatepageNums.length;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
    },
};